import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
import {TpHttpService} from '../../service/tp-http.service';
import {BaseResponse} from '../../entity/base-response';

@Component({
    selector: 'app-user-login',
    templateUrl: './user-login.component.html',
    styleUrls: ['./user-login.component.css']
})
export class UserLoginComponent implements OnInit {
    @ViewChild('loginFrame') loginFrame: ElementRef;
    constructor(private httpService: TpHttpService) {
    }

    ngOnInit() {
    }

    @Input()
    set show(show: boolean) {
        if (show) {
            const returnUrl = 'http://' + window.location.host + '/api/oauth2/fdd_uc/callback';
            console.log('获取三方登录URL, returnUrl:' + returnUrl);
            // this.loginFrame.nativeElement.setAttribute('src', 'http://www.baidu.com');
            this.httpService.get('/api/oauth2/fdd_uc?returnUrl=' + encodeURI(returnUrl)).subscribe((resp: BaseResponse<string>) => {
                this.loginFrame.nativeElement.setAttribute('src', resp.data);
            });
        }
    }

}
